﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using control.Biz;

namespace TrangSucShop.usercontrol
{
    public partial class user : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["KhachHang"] != null && Request.QueryString["cm"] != null)
                {
                    if (Request.QueryString["cm"] == "info")
                    {
                        mtv1.ActiveViewIndex = 0;
                        BizKhachHang _user = (BizKhachHang)Session["KhachHang"];
                        lbID.Text = _user.ID.ToString();
                        lbMa.Text = _user.MaKhachHang;
                        txtHoTen.Text = _user.TenKhachHang;
                        txtDiaChi.Text = _user.DiaChi;
                        txtEmail.Text = _user.Email;
                        txtSoDT.Text = _user.SoDienThoai.ToString();
                        TextBox1.Text = _user.TaiKhoan;
                        lbcommand.Text = "Thông Tin Cá Nhân";
                    }
                    else
                        mtv1.ActiveViewIndex = 1;
                }
                else
                    Response.Redirect("Default.aspx");
            }
        }

        protected void btdongy_Click(object sender, EventArgs e)
        {
            BizKhachHang user = (BizKhachHang)Session["KhachHang"];
            user.TenKhachHang = txtHoTen.Text;
            user.DiaChi = txtDiaChi.Text;
            user.Email = txtEmail.Text;
            user.TaiKhoan = TextBox1.Text;
            int sdt = 0;
            try { sdt = Convert.ToInt32(txtSoDT.Text); }
            catch { }
            user.SoDienThoai = sdt.ToString();
            bool resuilt = user.UpDate();
            if (resuilt == true)
                Label6.Text = "Thành công";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            BizKhachHang _user = (BizKhachHang)Session["KhachHang"];
            if (TextBox8.Text == _user.Password)
            {
                _user.Password = TextBox9.Text;
                bool resuilt = _user.UpDate();
                Label5.Text = "Đổi mật khẩu thành công";
            }
            else
            {
                Label5.Text = "Mật khẩu cũ không đúng !!!";
            }
        }
    }
}